package com.mapapp.flutter_mapapp.http.service;


import com.mapapp.flutter_mapapp.bean.AvatarBean;
import com.mapapp.flutter_mapapp.bean.CheckCodeBean;
import com.mapapp.flutter_mapapp.bean.DetailTree;
import com.mapapp.flutter_mapapp.bean.FixBean;
import com.mapapp.flutter_mapapp.bean.FixDetailBean;
import com.mapapp.flutter_mapapp.bean.HistoryDetail;
import com.mapapp.flutter_mapapp.bean.HouseholdProcess;
import com.mapapp.flutter_mapapp.bean.LoginBean;
import com.mapapp.flutter_mapapp.bean.MapDetailBean;
import com.mapapp.flutter_mapapp.bean.MapResult;
import com.mapapp.flutter_mapapp.bean.NewDataProcessBean;
import com.mapapp.flutter_mapapp.bean.OperationBean;
import com.mapapp.flutter_mapapp.bean.ResultMsg;
import com.mapapp.flutter_mapapp.bean.StepFloorBean;
import com.mapapp.flutter_mapapp.bean.TaskDetails;
import com.mapapp.flutter_mapapp.bean.TaskItem;

import java.util.List;

import okhttp3.MultipartBody;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.Multipart;
import retrofit2.http.POST;
import retrofit2.http.Part;
import retrofit2.http.Path;
import retrofit2.http.Query;
import rx.Observable;

public interface ApiService {

    //登录
    @POST("/app/login")
    Observable<ResultMsg<LoginBean>> login(@Query("username") String username,
                                           @Query("password") String password);

    //获取第一次地图的信息点
    @GET("/app/task/u_details")
    Observable<ResultMsg<MapResult>> getfirstdetails();

    //根据level获取地图的信息点
    @POST("/app/task/u_details")
    Observable<ResultMsg<MapResult>> getdetailsbylevel(@Query("level") int level);

    //根据level和bh地图的信息点
    @POST("/app/task/u_details")
    Observable<ResultMsg<MapResult>> getdetailsbylevelandbh(@Query("bh") String bh,
                                                            @Query("level") int level);

    @GET("/app/task/details_tree/{taskId}/{parentId}")
    Observable<ResultMsg<List<DetailTree>>> getTree(@Path("taskId") String taskId,
                                                    @Path("parentId") String parentId);


    /**
     * @param taskId id
     * @param state  1接受 1拒绝
     * @return bean
     */
    @GET("/app/task/accept/{taskId}/{state}")
    Observable<ResultMsg<List<DetailTree>>> acceptOrRefuseTask(@Path("taskId") String taskId,
                                                               @Path("state") int state);

    @GET("/app/task/details/{taskId}")
    Observable<ResultMsg<TaskDetails>> getTaskDetailsByTaskIdFirstLevel(@Path("taskId") String taskId);

    @GET("/app/task/details/{taskId}/{level}")
    Observable<ResultMsg<TaskDetails>> getTaskDetailsByTaskIdAndLevel(@Path("taskId") String taskId,
                                                                      @Path("level") int level);

    @GET("/app/task/list")
    Observable<ResultMsg<List<TaskItem>>> getRcTaskListByCurrentUser();

    @GET("/app/task/u_details")
    Observable<ResultMsg<TaskDetails>> getTaskDetailsByUserIdFirstLevel();

    @GET("/app/task/u_details/{level}")
    Observable<ResultMsg<TaskDetails>> getTaskDetailsByUserIdAndLevel(@Path("level") int level);

    @GET("/app/operation/process/{regionId}")
    Observable<ResultMsg<HouseholdProcess>> getProcessByRegionId(@Path("regionId") String regionId);


    /**
     * 获取户的数据信息，展示到操作页面.
     *
     * @param regionId id
     * @param type     0 新增；1 修改；2 覆盖：
     * @return bean
     */
    @GET("/app/operation/household/{regionId}/{type}")
    Observable<ResultMsg<NewDataProcessBean>> showProcess(@Path("regionId") String regionId,
                                                          @Path("type") int type);


    @GET("/app/region/tree/{parentId}")
    Observable<ResultMsg<List<DetailTree>>> getTreesByParentId(@Path("parentId") String parentId);


    //获取户调查历史列表
    @GET("/app/operation/listOperationHistory/{regionId}")
    Observable<ResultMsg<List<OperationBean>>> getOperationHistory(@Path("regionId") String regionId);

    @GET("/app/operation/getOperationHistory/{operationLogId}/0")
    Observable<ResultMsg<HistoryDetail>> getOperationHistoryDetail(@Path("operationLogId") String regionId);


    //提交步骤信息
    @POST("/app/operation/submitProcess")
    @FormUrlEncoded
    Observable<ResultMsg<String>> submitProcess(@Field("comment") String comment,
                                                @Field("endTime") String endTime,
                                                @Field("photoFolderName") String photoFolderName,
                                                @Field("processId") String processId,
                                                @Field("radioFolderName") String radioFolderName,
                                                @Field("regionId") String regionId,
                                                @Field("startTime") String startTime,
                                                @Field("state") int state,
                                                @Field("type") int type);


    //提交其他信息
    @POST("/app/operation/submitComment")
    @FormUrlEncoded
    Observable<ResultMsg<Object>> submitComment(@Field("message") String message,
                                                @Field("masterId") String masterId,
                                                @Field("radioName") String radioName);


    //提交分户信息
    @POST("/app/operation/submitSplitRegion")
    @FormUrlEncoded
    Observable<ResultMsg<Object>> submitSplitRegion(@Field("masterId") String masterId,
                                                    @Field("number") int number,
                                                    @Field("message") String message,
                                                    @Field("radioFolderName") String radioFolderName,
                                                    @Field("photoFolderName") String photoFolderName);

    //获取我的纠错列表
    @GET("/app/fix/listMyFix")
    Observable<ResultMsg<List<FixBean>>> listMyFix();

    //获取纠错详情
    @GET("/app/fix/getFixDetail/{auditId}")
    Observable<ResultMsg<FixDetailBean>> getFixDetail(@Path("auditId") String auditId);

    //获取纠错详情
    @POST("/app/operation/submitOperateInfo/{type}")
    @FormUrlEncoded
    Observable<ResultMsg<Object>> submitOperateInfo(@Path("type") String type,
                                                    @Field("regionId") String regionId,
                                                    @Field("processId") String processId,
                                                    @Field("fixType") String fixType);


    /**
     * @param folder 图片文件夹名称
     * @param name   图片文件名称，不带后缀
     * @param type   thumb 缩略图，ygf 高清图
     * @return 图片
     */
    @GET("/common/output/image/{folder}/{name}/{type}")
    Observable<ResultMsg<Object>> getImage(@Path("folder") String folder,
                                           @Path("name") String name,
                                           @Path("type") String type);


    /**
     * @param name 音频文件名称，不带后缀
     * @return 音频文件地址
     */
    @GET("/common/output/radio/{name}")
    Observable<ResultMsg<String>> getRadio(@Path("name") String name);


    //提交合户
    @POST("/app/operation/submitMergeRegion")
    @FormUrlEncoded
    Observable<ResultMsg<Object>> submitMergeRegion(@Field("masterId") String masterId,
                                                    @Field("attachIds") String attachIds,
                                                    @Field("message") String message,
                                                    @Field("radioFolderName") String radioFolderName,
                                                    @Field("photoFolderName") String photoFolderName);

    @GET("/app/getAppAvatar")
    Observable<ResultMsg<AvatarBean>> getAppAvatar();


    @POST("/common/input/uploadAvatar")
    @Multipart
    Observable<ResultMsg<String>> uploadAvatar(@Part MultipartBody.Part part);

    //根据用户搜索的地址，查找执行中的任务和完成任务的详情
    @GET("/app/task/u_details_address/{address}")
    Observable<ResultMsg<List<MapDetailBean>>> searchByaddress(@Path("address") String address);

    //获取楼幢下面的层和户的布局
    @GET("/app/task/u_building/{parentId}")
    Observable<ResultMsg<StepFloorBean>> getFloorInfo(@Path("parentId") String parentId);

    //获取验证码
    @GET("/app/pwd/code/{phone}")
    Observable<ResultMsg<String>> getCode(@Path("phone") String phone);

    //校验验证码
    @GET("/app/pwd/checkcode/{phone}/{code}")
    Observable<ResultMsg<CheckCodeBean>> checkCode(@Path("phone") String phone,
                                                   @Path("code") String code);

    //重置密码
    @GET("/app/pwd/resetpwd/{phone}/{tempToken}/{pwd}")
    Observable<ResultMsg<String>> resetPassword(@Path("phone") String phone,
                                                @Path("tempToken") String tempToken,
                                                @Path("pwd") String pwd);

    //修改密码
    @POST("/app/pwd/editPwd")
    Observable<ResultMsg<String>> editPassword(@Query("oldPwd") String oldPwd,
                                               @Query("newPwd") String newPwd);

    //获取用户所有任务的小区
    @GET("/app/task/community")
    Observable<ResultMsg<List<MapDetailBean>>> community();

}
